<template>
	<view class="container">
		<view class="search-view-container">
			<view class="search-view">
				<image class="search-view-icon" src="../../../static/images/search@3x.png"></image>
				<input
					maxlength="10"
					class="search-view-input"
					focus="true"
					placeholder="请输入教练昵称"
					placeholder-class="input-placeholder"
					@confirm="clickSearch"
					v-model="keyword"
				/>
			</view>
			<view class="search-view-btn-container"><view class="text" @click="clickSearch">搜索</view></view>
		</view>
		<view class="sell-container">
			<view v-if="playerList.length == 0" class="empty"><text>抱歉！没有找到符合条件的教练</text></view>
			<yue-wan v-else class="sell-item" v-for="(item, index) in playerList" :key="index" :itemData="item"></yue-wan>
		</view>
	</view>
</template>

<script>
import yueWan from '../../../components/yuewan-item.vue';
import { servePlayerList } from '../../../constant/customer.js';
export default {
	components: {
		yueWan
	},
	data() {
		return {
			playerList: [],
			query_filter: {
				gender: '',
				tags: '',
				keyword: '',
				pageIndex: 0,
				pageSize: 10
			},
			keyword: ''
		};
	},
	onLoad() {},
	onReachBottom() {
		this.query_filter.pageIndex++;
		this.searchPlayerList();
	},
	onPullDownRefresh() {
		this.query_filter.pageIndex = 0;
		this.searchPlayerList();
	},
	methods: {
		clickSearch() {
			this.query_filter.pageIndex = 0;
			this.query_filter.keyword = this.keyword;
			this.playerList = [];
			this.searchPlayerList();
		},
		async searchPlayerList() {
			if (this.query_filter.keyword) {
				let res = await servePlayerList(this.query_filter);
				if (res.TotalNumber > this.query_filter.pageIndex * this.query_filter.pageSize) {
					uni.stopPullDownRefresh();
					if (this.query_filter.pageIndex > 0) {
						for (let i = 0; i < res.Source.length; i++) {
							let obj = res.Source[i];
							this.playerList.push(obj);
						}
					} else {
						this.playerList = res.Source;
					}
					if (res.Source.length == 0) {
						this.pageIndex--;
					}
				} else {
					return;
				}
			} else {
				uni.showToast({
					title: '请输入查询内容',
					icon: 'none'
				});
				return;
			}
		},
		parentClickPlayer(playerId) {
			uni.navigateTo({
				url: '/packagePages/index/kongjian/index?playerId=' + playerId
			});
		}
	}
};
</script>

<style scoped lang="scss">
.container {
}

.sell-container {
	display: flex;
	flex-wrap: wrap;
	padding-left: 30rpx;
	padding-right: 30rpx;
	background: transp;
	justify-content: space-between;
	padding-bottom: 30rpx;
	padding-top: 20rpx;
	overflow: hidden;
	.sell-item {
		width: calc(50% - 12rpx);
		margin-bottom: 20rpx;
	}
}

.search-btn {
	margin-left: auto;
	margin-right: 20rpx;
	padding: 0 20rpx;
	height: 60rpx;
	color: #fff;
	font-size: 28rpx;
	line-height: 60rpx;
	border-radius: 8rpx;
	background-color: #bf3261;
}

.search-view-container {
	padding: 10rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding-left: 30rpx;
	padding-right: 30rpx;
	.search-view-btn-container {
		width: 70rpx;
		margin-left: 20rpx;
		font-size: $main-text-size-30;
		color: $main-text-color-gray-33;
	}
	.search-view {
		display: flex;
		align-items: center;
		background-color: $main-page-color;
		height: 60rpx;
		border-radius: 30rpx;
		width: 100%;
		.input-placeholder {
			font-size: $main-text-size-28;
			color: $main-text-color-grey;
		}

		&-icon {
			width: 30rpx;
			height: 30rpx;
			margin-left: 30rpx;
			margin-right: 20rpx;
		}
		&-input {
			font-size: $main-text-size-28;
			color: $main-text-color-gray-33;
			width: 80%;
		}
	}
}
.empty {
	height: 94vh;
	line-height: 320rpx;
	text-align: center;
	color: #b5b5b7;
	width: 100%;
}
</style>
